﻿<%@ page contentType="text/html; charset=utf-8"%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@ taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%@taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<c:set var="basePath" value="${pageContext.request.contextPath}"/>
<div id="updateDialog" class="crudDialog">
	<form id="updateForm" method="post" enctype="multipart/form-data">
		<input type="hidden" name = "stuId" value="${oneStudy.stuId}">
		<div class="form-group">
			<label for="name">主题</label>
			<input id="name" type="text" class="form-control" name="subject" maxlength="250" value="${oneStudy.subject}">
		</div>
		<div class="form-group">
			<label for="stumitter">提交人</label>
			<input id="stumitter" type="text" class="form-control" name="stumitter" maxlength="50" value="${oneStudy.submitter}">
		</div>
		<div class="form-group">
			<label for="stumitter"></label>
			<input id="file" type = "file"  class="form-control" name="fileName">
		</div>
		<div class="form-group text-right dialog-buttons">
			<a class="waves-effect waves-button" href="javascript:;" onclick="updateSubmit();">保存</a>
			<a class="waves-effect waves-button" href="javascript:;" onclick="updateDialog.close();">取消</a>
		</div>
	</form>
	<div class="progress">
		<div class="bar"></div >
		<div class="percent">0%</div >
	</div>
	<div id="status"></div>
</div>
<script>
function updateSubmit() {
	var stuSubject = $("#name").val();
	var stumitter = $("#stumitter").val();

	if($.trim(stuSubject) === ""){
		reConfirm("主题不能为空！");
		return;
	}
	if($.trim(stumitter) === ""){
		reConfirm("提交人不能为空！");
		return;
	}
	var updateForm = new FormData(document.getElementById("updateForm"));
	var bar = $(".bar");
	var percent = $(".percent");
	var status = $("#status");
    $.ajax({
        type: 'post',
        url: '${basePath}/manage/studymanage/update',
		processData:false,
		contentType:false,
        data: updateForm,
		beforeSend:function(){
			status.empty();
			var percentVal = '0%';
			bar.width(percentVal);
			percent.html(percentVal);
		},
		uploadProgress: function(event, position, total, percentComplete) {//上传的过程
			//position 已上传了多少
			//total 总大小
			//已上传的百分数
			var percentVal = percentComplete + '%';
			bar.width(percentVal);
			percent.html(percentVal);
			//console.log(percentVal, position, total);
		},
        success: function(result) {
			reConfirm(result.message);
			if (result.code == 1) {
				updateDialog.close();
				$table.bootstrapTable('refresh');
			}
        },
        error: function(XMLHttpRequest, textStatus, errorThrown) {
			$.confirm({
				theme: 'dark',
				animation: 'rotateX',
				closeAnimation: 'rotateX',
				title: false,
				content: textStatus,
				buttons: {
					confirm: {
						text: '确认',
						btnClass: 'waves-effect waves-button waves-light'
					}
				}
			});
        }
    });
}
function reConfirm(content) {
	$.confirm({
		title: "提示",
		content: content,
		autoClose: 'cancel|3000',
		backgroundDismiss: true,
		buttons: {
			cancel: {
				text: '确定',
				btnClass: 'waves-effect waves-button'
			}
		}
	});
}
</script>